﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace LevelEditor.Utils
{
    public class LeftMarginMultiplierConverter : IValueConverter
    {
        // Methods
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TreeViewItem item = value as TreeViewItem;
            if (item == null)
            {
                return new Thickness(0.0);
            }
            return new Thickness(this.Length * GetDepth(item), 0.0, 0.0, 0.0);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public static int GetDepth(TreeViewItem item)
        {
            for (FrameworkElement elem = item; elem.Parent != null; elem = elem.Parent as FrameworkElement)
            {
                TreeViewItem tvi = elem.Parent as TreeViewItem;
                if (tvi != null)
                {
                    return (GetDepth(tvi) + 1);
                }
            }
            return 0;
        }

        // Properties
        public double Length { get; set; }
    }


}
